﻿using IServices;
using Lazy.Captcha.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NDLS.WebApi.Model;
using NDLS.WebApi.Model.ModelVM;

namespace NDLS.WebApi.Controllers
{
    /// <summary>
    /// 基地相关操作
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BaseController : Controller
    {
        private readonly IUserService _userService;

        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="userService"></param>

        public BaseController(IUserService userService)
        {
            _userService = userService;
        }


        /// <summary>
        /// 查看基地信息
        /// </summary>
        /// <param name="trainingBase"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize(Policy = "AdminOrUser")]
        public List<MsgRes> GetBaseInfo(string trainingBase)
        {
            return _userService.GetBaseInfo(trainingBase);
        }

        /// <summary>
        /// 根据地区查找基地
        /// </summary>
        /// <param name="area"></param>
        /// <returns></returns>
        [HttpGet]
        public List<MsgRes> GetBaseInfoByArea(string area)
        {
            return _userService.GetBaseInfoByArea(area);
        }


        /// <summary>
        /// 删除基地
        /// </summary>
        /// <param name="no"></param>
        /// <param name="trainingBase"></param>
        /// <returns></returns>
        [HttpDelete]
        [Authorize(Policy = "Admin")]
        public MsgRes DeleteBase(int no,string trainingBase)
        {
            return _userService.DeleteBase(no,trainingBase);
        }

        /// <summary>
        /// 添加基地信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize(Policy = "Admin")]
        public MsgRes AddBase(BaseCourse baseCourse)
        {
            return _userService.AddBase(baseCourse);
        }

        /// <summary>
        /// 修改基地信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [Authorize(Policy = "Admin")]
        public MsgRes ModifyBase(BaseCourse baseCourse)
        {
            return _userService.ModifyBase(baseCourse);
        }

        /// <summary>
        /// 查看所有基地信息
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize(Policy = "AdminOrUser")]
        public object GetAllBase(int currentPage, int pageSize)
        {
            return _userService.GetAllBase(currentPage,pageSize);
        }
    }
}
